<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
<meta name="format-detection" content="telephone=no" />
<title>添加票务信息</title>
<meta content="" name="keywords" />
<meta content="" name="description" />
<meta content="" name="copyright" />
<meta content="" name="author" />
<meta name="robots" content="noarchive">
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/map.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script type="text/javascript" src="js/urlTool.js"></script>
<script type="text/javascript" src="js/mescroll.min.js"></script>
<link rel="stylesheet" href="css/public.css" />
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/swiper.min.css" />
<link rel="stylesheet" href="css/mescroll.min.css">
</head>

<body>
    <!--头部-->
    <div class="return_top bgyellow">
        <a href="viewtickettype.html">
            <span class="login_home cfff">返回票价列表</span>
        </a>
    </div>
    <!--//头部结束-->

    <!-- 添加票务信息开始 -->
    <div class="bgfff mb20 c333 pl20 pr20 pt20 pb120">
        <div class="mydata_inf mb20">
            <img src="temp/price.png" class="mydata_inf_img mr20">
            <input placeholder="票名" value="" keyboardtype="web-search" type="search" class="viewtickettype_input fz28" id="proName">
        </div>
        <div class="mydata_inf mb20">
            <img src="temp/price.png" class="mydata_inf_img mr20">
            <input placeholder="市场价" value="" keyboardtype="web-search" type="search" class="viewtickettype_input fz28" id="proPrice">
        </div>
        <div class="mydata_inf mb20">
            <img src="temp/price.png" class="mydata_inf_img mr20">
            <input placeholder="会员价" value="" keyboardtype="web-search" type="search" class="viewtickettype_input fz28" id="proMenmberPrice">
        </div>
        <div class="mydata_inf mb20">
            <img src="temp/price.png" class="mydata_inf_img mr20">
            <input placeholder="每日票量" value="" keyboardtype="web-search" type="search" class="viewtickettype_input fz28" id="proNum">
        </div>
        <div class="mydata_inf mb20">
            <img src="temp/price.png" class="mydata_inf_img mr20">            
            <textarea name="comment" form="usrform" placeholder="票信息" class="viewtickettype_textarea fz28 p20" id="proMsg"></textarea> 
        </div>
        <div id="proPicList" class="clear"></div>

        <div class="container">
            <!--    照片添加    -->
            <article class="upload-piclist">
               <div class="upload-file">
                <input type="file" id="file" name="file" multiple />
               </div>
            </article>
        </div>

        <div class="viewtickettypeadd_button">
            <button class="w100 car_cont_submit fz32 cfff" onclick="return viewFunction()">保存</button>
        </div>
    </div>
    <!--添加票务信息结束 -->


<!--底部-->
<div class="footerpage"></div>
<!--//底部-->
</body>
<script>
$(".footerpage").load("footer.html",'',function() {    
    $('#myCenter').addClass("select-two").children().attr("class","myCenterclick");
});
var id= getQueryVariable("id")||'';
if(id!=''){
    $(function(){
        sm.req({
            url: '/sysProduct/getMsg',
            dataType:'json', 
            type:'post',
            data: {id:id},
            done: function (res){
                var _str = '';
                if(res.code==200){
                    if(res['data']['proPicList'].length==0||''){
                        img_attPath ='temp\/noimg.png'
                        _str +='<div class="attimg">'
                                +'<img src="'+img_attPath+'"/>'
                        +'</div>';
                    }else{
                        for(var i=0;i<res.data.proPicList.length;i++){
                            img_attPath =fileUrl+res['data']['proPicList'][i]['attPath'];
                            _str +='<div class="attimg">'
                                    +'<img src="'+img_attPath+'" id="'+res.data.proPicList[i].id+'" alt="pic" class="img"/>'
                            +'</div>';
                        }
                    }
                    $('#proPicList').append(_str);
                    $("#proName").val(res.data.proName);
                    $("#proPrice").val(((res.data.proPrice)*0.01).toFixed(2));
                    $("#proMenmberPrice").val(((res.data.proMenmberPrice)*0.01).toFixed(2));
                    $("#proNum").val(res.data.proNum);
                    $("#proMsg").val(res.data.proMsg);
                }
                return false; 
            }
        })
        // return false;
    });
}

function viewFunction(){
    var proName = $('#proName').val();
    var proPrice = (($('#proPrice').val())*100).toFixed(0);
    var proMenmberPrice = (($('#proMenmberPrice').val())*100).toFixed(0);
    var proNum = $('#proNum').val();
    var proMsg =$('#proMsg').val();
    if (proName == "" || proName == undefined || proName == null || proName.length < 1){
        layer.open({
            content:'请填写票名！'
            ,btn: '我知道了'
        });
        return false;
    }

    if(proPrice == "" || proPrice == undefined || proPrice == null || proPrice.length < 1){
        layer.open({
            content:'请填写市场价！'
            ,btn: '我知道了'
        });
        return false;
    }
    
    if(proMenmberPrice == "" || proMenmberPrice == undefined || proMenmberPrice == null || proMenmberPrice.length < 1){
        layer.open({
            content:'请填写会员价！'
            ,btn: '我知道了'
        });
        return false;
    }

    if(proNum == "" || proNum == undefined || proNum == null || proNum.length < 1){
        layer.open({
            content:'请填写商品数量！'
            ,btn: '我知道了'
        });
        return false;
    } 

    if(proMsg == "" || proMsg == undefined || proMsg == null || proMsg.length < 1){
        layer.open({
            content:'请填写商品详情！'
            ,btn: '我知道了'
        });
        return false;
    }
    var param_data={'proName':proName,'proPrice':proPrice,'proMemberPrice':proMenmberPrice,'proNum':proNum,'proMsg':proMsg}
    if(id)param_data['id']=id;
    sm.req({
        url: '/sysProduct/update',
        dataType:'json', 
        type:'post',
        data:param_data,
        done: function (res){
            window.location.href = "viewtickettype.html";
            return false;
        }
    })
}
$("#file").on("change",function(){
    var filesize=0;
    var filemaxsize=10240;
    var filepath=file.value;
    if(filepath){
        filesize=$("#file")[0].files[0].size;
        var size=filesize/1024;
        if(size>filemaxsize){
            layer.open({
                content: '图片大小不能大于10M'
                ,btn: '我知道了'
            });
            file.value="";
            return false;
        }else if(size<=0){
            layer.open({
                content: '图片大小不能小于0M'
                ,btn: '我知道了'
            });
            file.value="";
            return false;
        }
    }else{
        return false;
    }
    var formData=new FormData();
    formData.append("file",$("#file")[0].files[0]);
    formData.append("objid",id);
    var objurl=getObjectURL($("#file")[0].files[0]);
    sm.req({
        url: '/upload/uploadPic',
        dataType:'json',
        type:'post',
        data:formData,
        processData:false,
        contentType:false,
        done: function (res){ 
            if(res.code==200){
                let html = document.createElement('div');
                html.className = 'upload-Picitem'
                html.innerHTML = '<img src="'+objurl+'" id="'+res.data.attachid+'" alt="pic" class="img">'
                $(".upload-piclist").append(html);
                id = res.data.objid;
            }
            layer.open({
                content:res.message
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
        }
    })
})

function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL!=undefined) { // basic
        url = window.createObjectURL(file);
    } else if (window.URL!=undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL!=undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}

// click
$(document).on('touchend','.img',function(){
    var attachId = $(this);
    layer.open({
        content: '确定要删除这张图片吗？'
        ,btn: ['确定', '取消']
        ,yes: function(index){
            sm.req({
                url: '/upload/deleteUpload',
                dataType:'json',
                type:'post',
                data: {'attachId':attachId.attr('id')},
                done: function (res){
                    attachId.parent().remove();
                    // $('.z_mask').addClass('hide');
                }
            })
            layer.close(index);
        }
    });
    
    return false;
})
</script>
</html>